package net.lzzy.Job;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

import java.util.List;

public class SparkJob {
    public static void main(String[] args) {
        SparkConf conf = new SparkConf().setAppName("SparkTextFile").setMaster("local");
        JavaSparkContext javaSparkContext = new JavaSparkContext(conf);
        JavaRDD<String> javaRDD = javaSparkContext.textFile("D:\\Spark\\trip.csv");
        JavaRDD<String> javaRDD1 = javaRDD.sortBy((String v1) -> {
            Trip trip = new Trip(Integer.parseInt(v1.split(",")[3]),Integer.parseInt(v1.split(",")[4]));
            return trip;
            },true,javaRDD.getNumPartitions());

        List<String> collect = javaRDD1.collect();
        for (String s : collect) {
            System.out.println(s);
        }
    }
}
